#ifndef PRODUCTSMODEL_H
#define PRODUCTSMODEL_H

#include "Product.h"
#include "ProductsListener.h"

#include <QStandardItemModel>

class ProductsModel : public QStandardItemModel
 {
     Q_OBJECT

 public:

    static const uint s_columns;

    enum COLUMN
    {
        PRODUCT_ID                   = 0,
        PRODUCT_NAME                 = 1,
        PRODUCT_DESCRIPTION          = 2,
        PRODUCT_PROVIDER             = 3,
        PRODUCT_PRICE_TYPE           = 4,
        PRODUCT_COST_ECOCITY         = 5,
        PRODUCT_PROFIT_RATE          = 6,
        PRODUCT_TAX_RATE             = 7,
        PRODUCT_PRICE_COOPE          = 8,
        PRODUCT_PRICE_SHOP           = 9,
        PRODUCT_PRICE_END_CUSTOMER   = 10
    };

    ProductsModel( const std::vector< ecocity::Product >& products,
                   QObject *parent = 0 );

    void reset( const std::vector< ecocity::Product >& products );

    QVariant headerData( int section, Qt::Orientation orientation, int role ) const;

    Qt::ItemFlags flags ( const QModelIndex & index ) const;

    ecocity::Product product( const QModelIndex& index ) const;

    std::vector< ecocity::Product > products( ) const;

    bool add_new_product( const ecocity::Product& product );

    // Load and save products in file
    void save( const QString& file_name ) const;
    bool load( const QString& file_name );

    int get_biggest_id( );
 };

#endif // PRODUCTSMODEL_H
